public class 字节码定义 {

    // 操作数类型
    public static final int 无效 = 0;
    public static final int 寄存器 = AssemblerParser.REG;
    public static final int 函数 = AssemblerParser.FUNC;
    public static final int 整数 = AssemblerParser.INT;
    public static final int 常量 = 1000;


    public static class 指令 {
        String 名称; // 例如 iadd、call
        int[] 操作数类型 = new int[3];
        int 操作数个数 = 0;

        public 指令(String 名称) {
            this.名称 = 名称;
        }

        public 指令(String 名称, int a) {
            this(名称, a, 0, 0);
            操作数个数 = 1;
        }


        public 指令(String 名称, int a, int b) {
            this(名称, a, b, 0);
            操作数个数 = 2;
        }

        public 指令(String 名称, int a, int b, int c) {
            this.名称 = 名称;
            操作数类型[0] = a;
            操作数类型[1] = b;
            操作数类型[2] = c;
            操作数个数 = 3;
        }
    }


    // 指令字节码(byte是有符号的; 指令取值[0, 255])
    public static final short 指令_IADD = 1;    // int add         // INSTR 是 INSTRUCTION 的缩写
    public static final short 指令_ISUB = 2;
    public static final short 指令_IMUL = 3;
    public static final short 指令_ILT = 4;     // int less than
    public static final short 指令_IEQ = 5;     // int equal
    public static final short 指令_FADD = 6;    // float add
    public static final short 指令_FSUB = 7;
    public static final short 指令_FMUL = 8;
    public static final short 指令_FLT = 9;     // float less than
    public static final short 指令_FEQ = 10;
    public static final short 指令_ITOF = 11;   // int to float
    public static final short 指令_CALL = 12;
    public static final short 指令_RET = 13;    // return with/without value
    public static final short 指令_BR = 14;     // branch
    public static final short 指令_BRT = 15;    // branch if true
    public static final short 指令_BRF = 16;    // branch if true
    public static final short 指令_CCONST = 17; // push constant char
    public static final short 指令_ICONST = 18; // push constant integer
    public static final short 指令_FCONST = 19; // push constant float
    public static final short 指令_SCONST = 20; // push constant string
    public static final short 指令_LOAD = 21;   // load from local context
    public static final short 指令_GLOAD = 22;  // load from global memory
    public static final short 指令_FLOAD = 23;  // field load
    public static final short 指令_STORE = 24;  // store in local context
    public static final short 指令_GSTORE = 25; // store in global memory
    public static final short 指令_FSTORE = 26; // field store
    public static final short 指令_PRINT = 27;  // print stack top
    public static final short 指令_STRUCT = 28; // push new struct on stack
    public static final short 指令_NULL = 29;   // push null onto stack
    public static final short 指令_POP = 30;    // throw away top of stack
    public static final short 指令_HALT = 31;   // 停止


    public static final 指令[] 指令集 = new 指令[]{
            null, // <无效指令>
            new 指令("iadd"), // index is the opcode
            new 指令("isub"),
            new 指令("imul"),
            new 指令("ilt"),
            new 指令("ieq"),
            new 指令("fadd"),
            new 指令("fsub"),
            new 指令("fmul"),
            new 指令("flt"),
            new 指令("feq"),
            new 指令("itof"),
            new 指令("call", 函数),
            new 指令("ret"),
            new 指令("br", 整数),
            new 指令("brt", 整数),
            new 指令("brf", 整数),
            new 指令("cconst", 整数),
            new 指令("iconst", 整数),
            new 指令("fconst", 常量),
            new 指令("sconst", 常量),
            new 指令("load", 整数),
            new 指令("gload", 整数),
            new 指令("fload", 整数),
            new 指令("store", 整数),
            new 指令("gstore", 整数),
            new 指令("fstore", 整数),
            new 指令("print"),
            new 指令("struct", 整数),
            new 指令("null"),
            new 指令("pop"),
            new 指令("halt")
    };

}
